﻿using KYSharp.SM;
using RuYiAdmin.Net.Common.Global;
using System;
using System.Text;

namespace RuYiAdmin.Net.Common.Utility
{
    /// <summary>
    /// SM2会话工具
    /// </summary>
    public class RuYiSM2Context
    {
        /// <summary>
        /// 公钥加密明文
        /// </summary>
        /// <param name="plainText">明文</param>
        /// <returns>密文</returns>
        public static String Encrypt(String plainText)
        {
            return SM2Utils.Encrypt_Hex(RuYiAdminGlobalContext.SM2Config.PublicKey, plainText, Encoding.UTF8);
        }

        /// <summary>
        /// 私钥解密密文
        /// </summary>
        /// <param name="cipherText">密文</param>
        /// <returns>明文</returns>
        public static String Decrypt(String cipherText)
        {
            return SM2Utils.Decrypt_Hex(RuYiAdminGlobalContext.SM2Config.PrivateKey, cipherText, Encoding.UTF8);
        }
    }
}
